package com.mobile.ado.setting;

import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceClickListener;

import com.mobile.ado.R;
import com.mobile.ado.setting.calendar.CalendarActivity;
import com.mobile.ado.setting.power.CustomizedPowerManger;
import com.mobile.ado.setting.ringtone.RingtoneSettingActivity;

public class SettingsActivity extends PreferenceActivity {

	private SettingsActivity activity;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		activity = this;

		addPreferencesFromResource(R.xml.setting_preferences);

		setupCalendarPreferenceScreen();

		setupRingtonePreferenceScreen();

		setupPowerPreferenceScreen();
	}

	private void setupPowerPreferenceScreen() {
		PreferenceScreen powerPreferenceScreen = (PreferenceScreen) findPreference(getString(R.string.pref_power_key));

		powerPreferenceScreen
				.setOnPreferenceClickListener(new OnPreferenceClickListener() {

					@Override
					public boolean onPreferenceClick(Preference arg0) {
						// TODO Auto-generated method stub
						CustomizedPowerManger powerManager = new CustomizedPowerManger(
								activity);
						powerManager.powerOff();
						return false;
					}
				});
	}

	private void setupRingtonePreferenceScreen() {
		PreferenceScreen ringtonePreferenceScreen = (PreferenceScreen) findPreference(getString(R.string.pref_ringtone_key));
		ringtonePreferenceScreen
				.setOnPreferenceClickListener(new OnPreferenceClickListener() {

					@Override
					public boolean onPreferenceClick(Preference paramPreference) {

						Intent intent = new Intent(activity,
								RingtoneSettingActivity.class);
						startActivity(intent);
						return false;
					}
				});
	}

	private void setupCalendarPreferenceScreen() {
		PreferenceScreen calendarPreferenceScreen = (PreferenceScreen) findPreference(getString(R.string.pref_calendar_key));
		calendarPreferenceScreen
				.setOnPreferenceClickListener(new OnPreferenceClickListener() {

					@Override
					public boolean onPreferenceClick(Preference paramPreference) {

						Intent intent = new Intent(activity,
								CalendarActivity.class);
						startActivity(intent);
						return false;
					}
				});
	}
}
